package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neuedu.entity.Nurselevel;
import com.neuedu.mapper.NurselevelMapper;
import com.neuedu.service.NurselevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 护理级别 服务实现类
 * </p>
 *
 * @author wangyu
 * @since 2025-10-22
 */
@Service
public class NurselevelServiceImpl extends ServiceImpl<NurselevelMapper, Nurselevel> implements NurselevelService {
    @Override
    @Cacheable(value = "nurselevel", key = "#status")
    public List<Nurselevel> list(Integer status) {
        QueryWrapper<Nurselevel> wrapper = new QueryWrapper<>();
        wrapper.eq("status", status)
            .orderByDesc("id");
        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public boolean check(String field, String value, Integer id) {
        QueryWrapper<Nurselevel> wrapper = new QueryWrapper<>();
        wrapper.eq(field, value);
        if (null != id) {
            wrapper.ne("id", id);
        }
        return this.count(wrapper) == 0;
    }

    @Override
    @CacheEvict(value = "nurselevel", key = "'list'")
    public boolean del(Integer id) {
        return this.removeById(id);
    }

    @Override
    @CacheEvict(value = "nurselevel", key = "'list'")
    public boolean add(Nurselevel nurselevel) {
        return this.save(nurselevel);
    }

    @Override
    @CacheEvict(value = "nurselevel", key = "'list'")
    public boolean update(Nurselevel nurselevel) {
        return this.updateById(nurselevel);
    }
}
